﻿using System;
using System.Collections;
using System.Collections.Generic;
using BLL;
using CrystalDecisions.CrystalReports.Engine;
using Model;

public partial class StatisticData_PIMStatistic_PRbyAllStepPIDDay : System.Web.UI.Page
{
    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }     
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        BindQCR();
        //BindPIDUID_Q();
    }

    private void BindQCR()
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("PRbyAllStepPIDDay.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text1"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        IList<Time_PRInfo> list = GetQData();

        //this.CrystalReportSource1.CacheDuration = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["CrystalImageCleaner-Sleep"]); 
        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
    }

    private IList<Time_PRInfo> GetQData()
    {
        IList<Time_PRInfo> oprs = new List<Time_PRInfo>();
        PIMTest opr = new PIMTest();
        oprs = opr.GetPIMTest_PRbyStepAllPIDDay(dt1, dt2);
        return oprs;
    }
}
